﻿using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using Sustainalytics.BusinessResearchProductStates.Entities.ResearchState;
using Sustainalytics.Entities.ProductInvolvement;
using System;
using System.Collections.Generic;

namespace Sustainalytics.Entities.SustainableProducts
{
    public class SustainableProductsIndicator
    {
        public virtual string IndicatorSymbol { get; set; }
        public virtual string CategorySymbol { get; set; }
        public virtual bool HasLevelOfInvolvement { get; set; } // (revenue range)
        public virtual PILevelOfInvolvement LevelOfInvolvement { get; set; }
        [BsonRepresentation(BsonType.String)] public virtual List<ClientFacingProduct> ClientFacingProducts { get; set; }
        public virtual string CategoryOfInvolvementType { get; set; }
        public virtual List<PIDataSource> Sources { get; set; }
        public virtual DateTime LastEdited { get; set; }
        public virtual string CategoryOfInvolvementDescription { get; set; }
        public virtual string RangeOwnership { get; set; }
        public virtual decimal? RevenuePercentage { get; set; }
        public virtual decimal? ProductRevenue { get; set; }
        public virtual string ProductInvolvementAnalysis { get; set; }
        public virtual string RevenueAnalysis { get; set; }
        public virtual string RevenueAnalysisSource { get; set; }
        public virtual int FinancialYear { get; set; }

        public string GetLevelOfInvolvement()
        {
            if (!HasLevelOfInvolvement)
                return "Not applicable";

            var start = LevelOfInvolvement.Start;
            var stop = Math.Abs(LevelOfInvolvement.Stop - 100) > float.Epsilon ? LevelOfInvolvement.Stop - 0.1 : LevelOfInvolvement.Stop;

            return $"{start}-{stop}%";
        }
    }
}
